﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Collections.ObjectModel;
using WebCrawler.Model;

namespace WebCrawler.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public MainViewModel()
        {
            //if (IsInDesignMode)
            //{
            //    // Code runs in Blend --> create design time data
            //}
            //else
            //{
            //    // Code runs "for real"
            //}

            MenuModelList = new ObservableCollection<MenuModel>();
            MenuModelList.Add(new MenuModel() { IconFont = "\xe629", Title = "百度语音合成", BackColor = "#a3cf62" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe6e7", Title = "720云 多图", BackColor = "#f8aba6" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe6e7", Title = "720云 视频", BackColor = "#2a5caa" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe6e7", Title = "720云 音频", BackColor = "#8e7437" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe74e", Title = "全景图转换", BackColor = "#78cdd1" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe652", Title = "单图下载", BackColor = "#decb00" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe617", Title = "CCTV", BackColor = "#999d9c" });
            MenuModelList.Add(new MenuModel() { IconFont = "\xe782", Title = "酷雷曼", BackColor = "#73b9a2" });

            MenuModel = MenuModelList[0];
            SwitchView = 0;
        }

        #region 属性
        public ObservableCollection<MenuModel> MenuModelList
        {
            get { return _menuModelList; }
            set { _menuModelList = value; RaisePropertyChanged(); }
        }
        private ObservableCollection<MenuModel> _menuModelList;

        public MenuModel MenuModel
        {
            get { return _menuModel; }
            set { _menuModel = value; RaisePropertyChanged(); }
        }
        private MenuModel _menuModel;

        public int SwitchView
        {
            get { return _switchView; }
            set { _switchView = value; RaisePropertyChanged(); }
        }
        private int _switchView;
        #endregion

        #region 命令
        public RelayCommand<MenuModel> SelectedCmd
        {
            get
            {
                if (_selectedCmd == null)
                    _selectedCmd = new RelayCommand<MenuModel>(selected);
                return _selectedCmd;
            }
        }
        public RelayCommand<MenuModel> _selectedCmd;

        #endregion

        #region 辅助函数
        private void selected(MenuModel menuModel)
        {
            MenuModel = menuModel;
            switch (MenuModel.Title)
            {
                case "百度语音合成": SwitchView = 0; break;
                case "720云 多图": SwitchView = 1; break;
                case "720云 视频": SwitchView = 2; break;
                case "720云 音频": SwitchView = 3; break;
                case "全景图转换": SwitchView = 4; break;
                case "单图下载": SwitchView = 5; break;
                case "CCTV": SwitchView = 6; break;
                case "酷雷曼": SwitchView = 7; break;
                default: SwitchView = 0; break;
            }
        }
        #endregion
    }
}